package com.winz.cultureapp.utils;

import android.annotation.SuppressLint;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

@SuppressLint("SimpleDateFormat")
public class FormatUtils {
    public static String millis2Str(long time) {
        Date dat = new Date(time);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dat);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String statusTimeStr = format.format(gc.getTime());
        return statusTimeStr;
    }


    public static String orderCreateTime2Str(long time) {
        Date dat = new Date(time);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dat);
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String statusTimeStr = format.format(gc.getTime());
        return statusTimeStr;
    }

    /**
     * 将long型的时间转变来style格式的时间
     */
    public static String millis2Str(long time, String style) {
        Date dat = new Date(time);
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTime(dat);
        SimpleDateFormat format = new SimpleDateFormat(style);
        String statusTimeStr = format.format(gc.getTime());
        return statusTimeStr;
    }

    public static String doubleOFormat(double value) {
        DecimalFormat format = new DecimalFormat("######0.00");
        return format.format(value);
    }

    public static String oneOFormat(double value) {
        DecimalFormat format = new DecimalFormat("######0.0");
        return format.format(value);
    }

    public static String towBitOformat(int value) {
        DecimalFormat format = new DecimalFormat("00");
        return format.format(value);
    }

    /**
     * @param
     * @return 该毫秒数转换为 * days * hours * minutes * seconds 后的格式
     * @author fy.zhang
     */
    public static String formatDuring(long mss) {
        long days = mss / (1000 * 60 * 60 * 24);
        long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
        long seconds = (mss % (1000 * 60)) / 1000;
        return days + " days " + hours + " hours " + minutes + " minutes "
                + seconds + " seconds ";
    }

    public static String formatDuring(long mss, String style) {
        long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
        long seconds = (mss % (1000 * 60)) / 1000;
        String[] split = style.split("-");
        return hours + split[0] + minutes + split[1] + seconds + split[2];
    }

    public static long millis2Day(long mss) {
        long days = mss / (1000 * 60 * 60 * 24);
        return days;
    }

    public static long millis2Hour(long mss) {
        long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
        return hours;
    }

    public static long millis2Min(long mss) {
        long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
        return minutes;
    }

    public static long millis2Sec(long mss) {
        long seconds = (mss % (1000 * 60)) / 1000;
        return seconds;
    }

    public static long str2Millis(String date, String style) {
        Date dateTime = null;
        long time = 0;
        try {
            SimpleDateFormat oldFormat = new SimpleDateFormat(style);
            dateTime = oldFormat.parse(date);
            time = dateTime.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return time;
    }

}
